#!/bin/csh -f
# script to do some postprocesing after export
# argument: aqua export root directory

if ( $#argv != 1 ) then
    echo "usage: postexp  export_dir_root"
    exit (1)
endif

if ( ! -d $1 ) then
    echo $1 "is not a directory"
    exit (1)
endif

# modify makefile
cd $1/src
gawk -v "root=$1:t" ' \
    $1 == "MYROOT"   { print "MYROOT = ????" ; next } \
    $1 == "AQUAROOT" { print "AQUAROOT = $(MYROOT)/" root; next } \
    $1 == "EXPORT"   { print "EXPORT   = /tmp/" root; next } \
                     { print } \
    ' makefile > makefile.nw
    \mv makefile.nw makefile
echo "modified $1/src/makefile"

# modify aquanal.pl
cd $1/scripts
gawk ' \
    NR == 1 { print "#\!/usr/local/bin/perl -w"; next } \
	    { print $0 } \
    ' aquanal.pl > aquanal.pl.nw
    \mv aquanal.pl.nw aquanal.pl
    chmod +x aquanal.pl
echo "modified $1/scripts/aquanal.pl"

# modify procheck setup.scr
#cd $1/procheck
#gawk ' \
#    /set *prodir/      { print "set    prodir =  @@_program_directory_@@"; next }\
#    /setenv *prodir/   { print "setenv prodir    @@_program_directory_@@"; next }\
#    /setenv *aquaroot/ { print "if ( ! $?aquaroot )         setenv aquaroot   @@_program_directory_@@"; next }\
#                       { print } \
#    ' setup.scr > setup.scr.nw
#    \mv setup.scr.nw setup.scr
#echo "modified $1/procheck/setup.scr"


# modify aqsetup[i]
cd $1
chmod +x aqsetup aqsetupi >& /dev/null
echo "modified $1/aqsetupi[i]"
